package route

import (
	"time"

	"gitee.com/jiebaiyou/formflow/api/controller"
	"gitee.com/jiebaiyou/formflow/bootstrap"
	"gitee.com/jiebaiyou/formflow/pkg/storage/redis"
	"gitee.com/jiebaiyou/formflow/pkg/storage/sqlite"
	"gitee.com/jiebaiyou/formflow/repository"
	"gitee.com/jiebaiyou/formflow/service"
	"github.com/gin-gonic/gin"
)

// NewQuestionRouter 设置题目相关路由
func NewQuestionRouter(env *bootstrap.Config, timeout time.Duration, db sqlite.DB, cache redis.Database, group *gin.RouterGroup) {
	// 初始化题目仓储
	qr := repository.NewQuestionRepository(db, cache)
	// 初始化题目服务
	qs := service.NewQuestionService(qr, timeout)
	// 初始化题目控制器
	qc := &controller.QuestionController{
		QuestionService: qs,
		Env:             env,
	}

	// 题目模板
	group.GET("/templates", qc.GetQuestionTemplates)       // 获取所有题目模板
	group.GET("/templates/:type", qc.GetQuestionTemplates) // 获取指定类型的题目模板

	// 题目CRUD操作
	group.POST("/:type", qc.CreateQuestion) // 创建题目
	group.PUT("/:id", qc.UpdateQuestion)    // 更新题目
	group.DELETE("/:id", qc.DeleteQuestion) // 删除题目
	group.GET("/:id", qc.GetQuestionByID)   // 获取单个题目
	group.GET("", qc.ListQuestions)         // 题目列表查询
}
